/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package shoppingClient;
    
/**
 *
 * @author MinhDuc
 */
public class ProductInShowlistPanel extends javax.swing.JPanel {
    private Product product;
    private ShoppingClientGUI parentsFrame;
    
    /**
     * Creates new form ProductPanel
     * @param product
     * @param parents
     */
    public ProductInShowlistPanel(Product product,ShoppingClientGUI parents) {
        this.product = product;
        this.parentsFrame = parents;
        initComponents();
        
    }
    
    


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        name = new javax.swing.JLabel();
        price = new javax.swing.JLabel();
        avaiableAmount = new javax.swing.JLabel();
        addOneItem = new javax.swing.JButton();

        setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(255, 0, 0), new java.awt.Color(0, 0, 204), null, null));
        setLayout(new java.awt.GridLayout(0, 1, 0, 10));

        name.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        name.setText(getNameofProduct());
        name.setToolTipText("");
        add(name);

        price.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        price.setText(getPriceLabel());
        add(price);

        avaiableAmount.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        avaiableAmount.setText(getAvaiableAmountLabel());
        add(avaiableAmount);

        addOneItem.setActionCommand("add one item");
        addOneItem.setLabel("add one Item");
        addOneItem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addOneItem(evt);
            }
        });
        addOneItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addOneItemActionPerformed(evt);
            }
        });
        add(addOneItem);
        addOneItem.getAccessibleContext().setAccessibleName("addOneItem");
    }// </editor-fold>//GEN-END:initComponents
    private String getNameofProduct(){
        return product.getName();
    }
    
    public String getPriceLabel(){
        StringBuffer bf=new StringBuffer();              
        bf.append("price :");              
        bf.append(product.getPrice());       
        bf.append(" €");    
        return bf.toString();
    }
    
    private String getAvaiableAmountLabel(){
        StringBuilder bf = new StringBuilder();
        bf.append("avaiable amount in shop :");
        bf.append(product.getAvaiableAmount());
        return bf.toString();
    }
    
    private void addOneItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOneItemActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_addOneItemActionPerformed

    private void addOneItem(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addOneItem
        parentsFrame.addOneItem(product.getName());
    }//GEN-LAST:event_addOneItem


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addOneItem;
    private javax.swing.JLabel avaiableAmount;
    private javax.swing.JLabel name;
    private javax.swing.JLabel price;
    // End of variables declaration//GEN-END:variables

}
